package com.xpgk.mvc.propgandaThings;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jfinal.log.Log;
import com.jfinal.template.stat.ast.Set;
import com.xpgk.annotation.Service;
import com.xpgk.constant.ConstantRender;
import com.xpgk.dto.RenderBean;
import com.xpgk.mvc.base.BaseService;
import com.xpgk.mvc.intoPersonnel.IntoExperience;
import com.xpgk.mvc.intoPersonnel.IntoPersonnel;

@Service(name = PropgandaThingsService.serviceName)
public class PropgandaThingsService extends BaseService {
	
	@SuppressWarnings("unused")
	private static final Log log = Log.getLog(PropgandaThingsService.class);

	public static final String serviceName = "propgandaThingsService";
	
	/**
	 * 添加产品
	 * @param user
	 * @param organIds
	 * @return
	 */
	public RenderBean addProduct(PropgandaThings product,String  cudid){
		RenderBean result = new RenderBean();
		product.set("orgids", cudid);
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("column", PropgandaThings.column_proBh);
		String sql = getSqlByBeetl(PropgandaThings.sqlId_column, param);
		PropgandaThings oProduct = PropgandaThings.dao.findFirst(sql, product.getStr(PropgandaThings.column_proBh));
		if(null == oProduct){
		if(product!=null )
		{	
				if(!product.save())
				{
					result.setCode(ConstantRender.render_error_code);
					
				}else{
					result.setCode(ConstantRender.render_success_code);
					
				}
			
	}else{
		result.setCode(ConstantRender.render_error_code);
	}
		}else{
		result.setCode("编号已存在");
	}
		
	return  result;
	}
	
	/**
	 * 编辑产品
	 * @param user
	 * @param organIds
	 * @return
	 */
	public RenderBean upProduct(PropgandaThings product,String  cudid){
		
		RenderBean result = new RenderBean();
		product.set("orgids", cudid);
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("column", PropgandaThings.column_proBh);
		String sql = getSqlByBeetl(PropgandaThings.sqlId_column, param);
		PropgandaThings oProduct = PropgandaThings.dao.findFirst(sql, product.getStr(PropgandaThings.column_proBh));
	
		if(null == oProduct){
			product.update();
			result.setCode(ConstantRender.render_success_code);
		}else{
			
			if(product.getStr(PropgandaThings.column_orgids).equals(oProduct.getStr(PropgandaThings.column_orgids))){
				if(product.getStr(PropgandaThings.column_ids).equals(oProduct.getStr(PropgandaThings.column_ids))){
					product.update();
					result.setCode(ConstantRender.render_success_code);
				}else{
					result.setCode(ConstantRender.render_error_code);
					result.setMsg("产品编号重复！");
				}
				
				
			}else{
				product.update();
				result.setCode(ConstantRender.render_success_code);
			
		}
		}
		return result;

	}

}
